<?php 
	echo "
	<div class='lp1 pad15' style = 'background: none; '>
		<div class='bpad15'>
			<div class = 'pageHeading'>".Language::Get('Available chats').":</div>
			<div id = 'chatRoomsContainer'>";
	
	echo "
        <table cellpadding='0' cellspacing='0' width='100%' style = 'margin-bottom: 15px; '>";
	
	//search row			
	echo "	<tr class='lp1'>
		    	<td class='bpad10 dq-input-text' style = 'padding-top: 10px; '>";
					XHTML::Form('/chats/rooms/', 'GET', array('id' => 'searchForm', 'onsubmit' => '//return BeforeNewTopic();'));
		    			XHTML::InputText('name', '', array('id' => 'searchString'));
	echo "			</form>
				</td>
				<td style = 'padding-left: 10px; ' colspan = '2'>
					<div id='btnSearch' style = ''>".Language::Get('Search', 'CAPITALIZE')."</div>
				</td>
		  	</tr>";
	
	//rooms list
	foreach ($this->data['rooms'] as $room)
			{
				echo "
					<tr class='lp1' name = ''>
            			<td align='left' class='tpad15 bpad15'>";
							XHTML::Anchor('/chats/room/'.$room['id'], $room['name']);
				echo "	</td>
						<td style = 'padding-left: 10px; ' width = '80'>";
							if ($room['client_id'] == HTTPContext::$session['client']['id'])
							{
								echo "								
								<div class = 'btnDelete{$room['id']}' style = ''>".Language::Get('Delete', 'CAPITALIZE')."</div>
								<script>
									$('.btnDelete{$room['id']}').dqButton({type: 3, action: '/chats/deleteroom/{$room['id']}', clickType: 'href', live: false});	
									$('.btnDelete{$room['id']}').click(function() {return confirm('Do you really want to delete this chat room?')});	
									$('.btnDelete{$room['id']} .btnType-3-left').addClass('btnType-4-left-select');	
									$('.btnDelete{$room['id']} .btnType-3-center').addClass('btnType-4-center-select');	
									$('.btnDelete{$room['id']} .btnType-3-right').addClass('btnType-4-right-select');														
								</script>";
							}
				echo "	</td>
						<td style = 'padding-left: 5px; ' width = '80'>
							<div class = 'btnJoin{$room['id']}' style = ''>".Language::Get('Join')."</div>
							<script>
								$('.btnJoin{$room['id']}').dqButton({type: 4, action: '/chats/room/{$room['id']}', clickType: 'href', live: false});	
								$('.btnJoin{$room['id']} .btnType-4-left').addClass('btnType-4-left-select');	
								$('.btnJoin{$room['id']} .btnType-4-center').addClass('btnType-4-center-select');	
								$('.btnJoin{$room['id']} .btnType-4-right').addClass('btnType-4-right-select');														
							</script>
						</td>
				</tr>";
			}	
	echo "
          <tr class='lp1'>
		    <td class='bpad10 dq-input-text' style = 'padding-top: 10px; '>";
				XHTML::Form('/chats/rooms/', 'POST', array('id' => 'newForm', 'onsubmit' => 'return BeforeNewTopic();'));
		    		XHTML::InputText('name', '', array('id' => 'roomName'));
	echo "		</form>
			</td>
			<td style = 'padding-left: 10px; ' colspan = '2'>
				<div id='btnAdd' style = ''>".Language::Get('New topic', '')."</div>
			</td>
		  </tr>	
        </table>";

	//pagination
	echo HtmlsHelper::Pagination($this->data['num_rows']);

	echo "	</div>
		</div>
	</div>";
	
	XHTML::Script('text/javascript', "
		function BeforeNewTopic()
		{
			if ($('#roomName').val() == '')
			{
				alert('".Language::Get('Fill in room name')."');
				return false;
			}
			else
			{
				return true;
			}
		}
	");
?>

<script type="text/javascript">
	$('#btnAdd').dqButton({type: 5, action: "$('#newForm').submit()", clickType: 'js', live: true});	
	$('#btnSearch').dqButton({type: 5, action: "$('#searchForm').submit()", clickType: 'js', live: true});	
	$('.dq-input-text').dqInput();
		
</script>